﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DesignPatternsConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Starting Main");
            Test2.EchoAndReturn("Echo!");
            Console.WriteLine("After echo");
            //Reference a static field in Test
            string y = Test2.x;
            //Use the value just to avoid compiler cleverness
            if (y != null)
            {
                Console.WriteLine("After field access");
            }
            Console.ReadKey();
        }
    }

    /// <summary>
    /// 只有在第一次使用到Test1的时候，才会初始化Test1.x
    /// </summary>
    class Test1
    {
        public static string x = EchoAndReturn("In type initializer");

        public static string EchoAndReturn(string s)
        {
            Console.WriteLine(s);
            return s;
        }
    }
    class Test2
    {
        public static string x = EchoAndReturn("In type initializer");

        // Defines a parameterless constructor.
        static Test2()
        {
        }

        public static string EchoAndReturn(string s)
        {
            Console.WriteLine(s);
            return s;
        }
    }
    static class Test3
    {
        public static string x = EchoAndReturn("In type initializer");

        public static string EchoAndReturn(string s)
        {
            Console.WriteLine(s);
            return s;
        }
    }
}
